package com.debt.canal.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author GaoZeXi 2020-7-21 21:12:32
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 定义队列名称
     */

    public static final String CUSTOM_QUEUE="custom_queue";

    /**
     * 定义交换机名称
     */
    public static final String CUSTOM_EXCHANGE="custom_exchange";


    /**
     * 声明队列
     */
    @Bean(CUSTOM_QUEUE)
    public Queue getCustomQueue(){
        return new Queue(CUSTOM_QUEUE);
    }

    /**
     * 声明交换机
     * 生成一个 name=exchange_name的,可序列化的  广播模式的交换机
     */
    @Bean(CUSTOM_EXCHANGE)
    public Exchange getCustomExchange(){
        return ExchangeBuilder.fanoutExchange(CUSTOM_EXCHANGE).durable(true).build();
    }

    /**
     * 声明绑定关系
     */
    @Bean
    public Binding customBinding(@Qualifier(CUSTOM_QUEUE) Queue queue,@Qualifier (CUSTOM_EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }



}
